package com.example.piedritas;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class Activity2 extends Activity implements OnClickListener, OnLongClickListener {
	ImageButton piedra;
	ImageButton papel;
	ImageButton tijera;
	ImageButton lagarto;
	ImageButton spock;
	ImageButton confirmar;
	private int modoDeJuego;
	private int jugador1;
	TextView nombrePlayer1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_activity2);
		
		piedra = (ImageButton) findViewById(R.id.piedra); 
		piedra.setOnClickListener(this);
		papel = (ImageButton) findViewById(R.id.papel);	
		papel.setOnClickListener(this);
		tijera = (ImageButton) findViewById(R.id.tijeras); 
		tijera.setOnClickListener(this);
		lagarto = (ImageButton) findViewById(R.id.lagarto);
		lagarto.setOnClickListener(this);
		spock = (ImageButton) findViewById(R.id.spok); spock.
		setOnClickListener(this);
		nombrePlayer1 = (TextView) findViewById(R.id.vistaDeNombreJ1);
		nombrePlayer1.setText(nombrePlayer1.getText().toString()+MainActivity.getJugador1Nombre());
		
		confirmar = (ImageButton) findViewById(R.id.confirm); 
		confirmar.setOnLongClickListener(this);
		
		Bundle i = this.getIntent().getExtras();
		this.modoDeJuego = i.getInt("valorDeJuego");
		Toast toas = Toast.makeText(this, "Turno de "+ MainActivity.getJugador1Nombre(),
				Toast.LENGTH_SHORT);
		toas.show();
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity2, menu);
		return true;
	}
	
	@Override
	protected void onRestart() {
		finish();
		super.onRestart();
	}

	@Override
	public boolean onLongClick(View v) {
		if(confirmar.getDrawable() != null){
			Intent i = new Intent(Activity2.this, Activity3.class);
			i.putExtra("valorDeJuego", this.modoDeJuego);
			i.putExtra("Jugador1", this.jugador1);
			startActivity(i);
		}
		return false;
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.piedra:
			confirmar.setImageDrawable(this.piedra.getDrawable());
			this.jugador1= 1;
			break;
		case R.id.papel:
			confirmar.setImageDrawable(this.papel.getDrawable());
			this.jugador1= 2;
			break;
		case R.id.tijeras:
			confirmar.setImageDrawable(this.tijera.getDrawable());
			this.jugador1= 3;
			break;
		case R.id.lagarto:
			confirmar.setImageDrawable(this.lagarto.getDrawable());
			this.jugador1= 4;
			break;
		case R.id.spok:
			confirmar.setImageDrawable(this.spock.getDrawable());
			this.jugador1= 5;
			break;
		}
	}

}
